﻿using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
using ContosoProviders;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration.Claims;
namespace CustomMemberShipProviderWP.ChangePassword
{
    [ToolboxItemAttribute(false)]
    public partial class ChangePassword : WebPart
    {
        // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
        // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
        // for production. Because the SecurityPermission attribute bypasses the security check for callers of
        // your constructor, it's not recommended for production purposes.
        // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
        public ChangePassword()
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            bool changed = false;
            string LoginName = string.Empty;
            SPClaimProviderManager ClaimManager = SPClaimProviderManager.Local;
            if (ClaimManager != null)
            {
                LoginName = ClaimManager.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName).Value;
            }
            BaseMember mem = new BaseMember();
            try
            {

                if (mem.ChangePassword(LoginName, txtOldPassword.Text, txtNewPassword.Text))
                    lblError.Text = "Success";
                else
                    lblError.Text = "Failed";
            }
                
            catch (Exception ex)
            {
                lblError.Text = ex.ToString();
            }
            
        }
    }
}
